﻿
if (typeof NTTHAO == "undefined" || !NTTHAO) {
    /**
     * The NTTHAO global namespace object.  If NTTHAO is already defined, the
     * existing NTTHAO object will not be overwritten so that defined
     * namespaces are preserved.
     * @class NTTHAO
     * @static
     */
    var NTTHAO = {};
}

/**
 * Returns the namespace specified and creates it if it doesn't exist
 * <pre>
 * NTTHAO.namespace("property.package");
 * NTTHAO.namespace("NTTHAO.property.package");
 * </pre>
 * Either of the above would create NTTHAO.property, then
 * NTTHAO.property.package
 *
 * Be careful when naming packages. Reserved words may work in some browsers
 * and not others. For instance, the following will fail in Safari:
 * <pre>
 * NTTHAO.namespace("really.long.nested.namespace");
 * </pre>
 * This fails because "long" is a future reserved word in ECMAScript
 *
 * @method namespace
 * @static
 * @param  {String*} arguments 1-n namespaces to create 
 * @return {Object}  A reference to the last namespace object created
 */
NTTHAO.namespace = function() {
    var a=arguments, o=null, i, j, d;
    for (i=0; i<a.length; i=i+1) {
        d=a[i].split(".");
        o=NTTHAO;

        // NTTHAO is implied, so it is ignored if it is included
        for (j=(d[0] == "NTTHAO") ? 1 : 0; j<d.length; j=j+1) {
            o[d[j]]=o[d[j]] || {};
            o=o[d[j]];
        }
    }

    return o;
};

/**
 * namespace NTTHAO.util
 */
NTTHAO.namespace('util');
NTTHAO.util.getElement = function(el) {
    if(!YAHOO.lang.isObject(el)) {
        return document.getElementById(el);
    }
    return el;
}

NTTHAO.util.getAbsoluteXY = function(el) {
    if(!YAHOO.lang.isObject(el)) {
        el = document.getElementById(el);
    }
    if(el == null) {
        return null;
    }
    
    var yPos = el.offsetTop;
    var xPos = el.offsetLeft;
    var tempEl = el.offsetParent;
    while (tempEl != null) {
        xPos += tempEl.offsetLeft;
        yPos += tempEl.offsetTop;
        tempEl = tempEl.offsetParent;
    }

    return [xPos, yPos];
}

NTTHAO.util.isImageFile = function(filename) {
    var fileEx = (/[.]/.exec(filename)) ? /[^.]+$/.exec(filename)[0] : null;
    return (fileEx != null) && (".jpg .jpeg .jpe .png .gif .bmp ".indexOf('.'+fileEx.toLowerCase()+' ') >= 0);
}